#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+7;
int a[N],last[2];
bool f[N];
mt19937_64 rd(time(0));
signed main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int T;
	scanf("%lld",&T);
	while (T--){
		int n,mx=0;
		scanf("%lld",&n);
		for (int i=0;i<n;++i)
			scanf("%lld",a+i);
		if (n>15){
			printf("%lld",rd());
			continue;
		}
		for (int i=0;i<(1<<n);++i){
			last[0]=last[1]=-1;
			for (int j=0;j<n;++j)
				f[j]=((i>>j)&1);
			int ans=0;
			for (int j=0;j<n;++j){
				if (last[f[j]]!=-1 && a[j]==a[last[f[j]]]) ans+=a[j];
				last[f[j]]=j;
			}
			mx=max(mx,ans);
		}
		printf("%lld\n",mx);
	}
	return 0;
}
